package com.night.administration.rabbitmq;

import com.night.administration.service.CourseManagerService;
import com.night.common.entity.administration.vo.CourseManagerVo;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @ClassName: CourseManagerConsumer
 * @Description: //TODO
 * @author: LZJ
 * @date: 2022/10/27-9:41
 * @version: v1.0
 */
@Component
public class CourseManagerConsumer {
    //处理消息可以添加三个参数
    // String str,      消息正文
    // Message message, 消息对象
    // Channel channel  信道
    @Resource
    private CourseManagerService courseManagerService;

    @RabbitListener(queues = "queueCourseArrangement")
    public void receiveCourseArrangement(CourseManagerVo courseManagerVo, Message message, Channel channel) throws IOException {
        //确认排课时间没有冲突后的消息
        courseManagerService.insert(courseManagerVo);
        //long deliveryTag, 标记
        // boolean multiple,  一次是否同时确认多条消息(比当前tag值小的消息一起确认)
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
